package com.hgsoft.service;

import java.util.LinkedList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hgsoft.dao.StationDao;
import com.hgsoft.entity.Station;
import com.hgsoft.util.Order;
import com.hgsoft.util.Property;

@Service
public class StationService extends BaseService<Station> {

	@Resource(type=StationDao.class)
	public void setDao(StationDao dao) {
		super.setDao(dao);
	}

	@Override
	public StationDao getDao() {
		return (StationDao) super.getDao();
	}

	public Integer getLineByStation(String station) {
		List<Station> list = getDao().findAll(Order.asc("id"), Property.eq("name", station));
		if (list != null && !list.isEmpty()) {
			return list.get(0).getLine();
		} else {
			return null;
		}
	}

	public Integer getLineByLoc(String loc) {
		List<Station> list = getDao().findAll(Order.asc("id"), Property.eq("pinyin", loc));
		if (list != null && !list.isEmpty()) {
			return list.get(0).getLine();
		} else {
			return null;
		}
	}

	public List<String> findByLine(Integer line) {
		List<String> list = new LinkedList<String>();
		List<Station> queryList = getDao().findAll(Order.asc("serialNum"), Property.eq("line", line), Property.eq("type", 1));
		if (queryList != null && !queryList.isEmpty()) {
			for (Station s : queryList) {
				list.add(s.getName());
			}
		}
		return list;
	}

}
